const express = require('express');
const router = express.Router();
const multer = require('multer');
const uuid = require('uuid');
const fs = require('fs');
const app = express();

const upload = multer({dest: 'upload/'});


app.post('/upload', upload.single('file'), (req, res, next) => {
  console.log('文件。。。')
  res.send({
    ret_code: '0'
  })
})

app.get('/form', (req, res, next) => {
  const form = fs.readFileSync('./form.html', {encoding: 'utf8'});
  res.send(form);
})

// const storage = multer.diskStorage({
//   destination(req, file, cb){
//     cb(null, 'tmp') // 设置文件保存的文件夹
//   },
//   filename(req, file, cb){
//     cb(null, `${uuid.v1()}.wav`)  // 设置保存的文件名
//   }
// })

// single 代表上传一个文件 ， 参数为前端上传时的name

// router.post('/upload', multer({storage: storage}).single('file'), (req, res, next) => {
//   console.log(req.file.path)
// })

console.log('runing......')

app.listen(3000)

